package com.example.hfut_edu;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class page_home extends AppCompatActivity {
    public static page_home home_obg = null;
    LinearLayout head, body, foot;
    Button btn_signout;
    TextView username, useraccount, text_zhuanye,text_banji,text_xiaoqv,text_pyfa,text_rxrq;
    ImageView img_toux;
    Bitmap bitmap_img;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_page_home);
        home_obg =this;

        head = findViewById(R.id.head);
        body = findViewById(R.id.body);

        username = findViewById(R.id.username);
        useraccount = findViewById(R.id.useraccount);
        text_zhuanye = findViewById(R.id.text_zhuanye);
        text_banji = findViewById(R.id.text_banji);
        text_xiaoqv = findViewById(R.id.text_xiaoqv);
        text_pyfa = findViewById(R.id.text_pyfa);
        text_rxrq = findViewById(R.id.text_rxrq);

        img_toux = findViewById(R.id.img_toux);

        try {
            //读取信息并赋值
            String jsonstr=rwSPdata("r","userdata","");
            String[] jsonlist = new String[26];
            String jsonstr1=jsonstr.replace("{","").replace("}","").replace("[","").replace("]","").replace("'","");
            jsonlist=jsonstr1.split(",");
            username.setText(jsonlist[1].split(":")[1]);
            useraccount.setText(jsonlist[0].split(":")[1]);
            text_zhuanye.setText(jsonlist[10].split(":")[1]);
            text_banji.setText(jsonlist[13].split(":")[1]);
            text_xiaoqv.setText(jsonlist[14].split(":")[1]);
            text_pyfa.setText(jsonlist[16].split(":")[1]);
            text_rxrq.setText(jsonlist[24].split(":")[1]);
        }catch (Exception e){}


    }


    public String rwSPdata(String flag,String key,String value){
        SharedPreferences testSP= getSharedPreferences("testSP", Activity.MODE_PRIVATE);
        switch (flag){
            case "w":
                SharedPreferences.Editor editor = testSP.edit();
                editor.putString( key, value );
                editor.apply();
                return "";
            case "r":
                return testSP.getString( key, "" );
            default:
                return "";
        }
    }


}